var app = getApp()
var template = require('../../../../template/lvtongTemplate.js');
Page({
  /**
   * 页面的初始数据
   */
  data: {
    did: '',
    windowWidth: 0,
    windowHeight: 0,
    t_status: false,
    isopera: false,
  },
  docterorder: function (e) {
    // console.log(e);
    const state = e.currentTarget.dataset.dex;
    wx.navigateTo({
      url: '/hyb_yl/lvtongserver/pages/docorder/docorder?state=' + state,
    })
  },
  patientman: function (e) {
    const state = e.currentTarget.dataset.dex;
    var zid = e.currentTarget.dataset.zid;
    // if (state == 3) {
    //   wx.navigateTo({
    //     url: '/hyb_yl/mysubpages/pages/patientgroup/patientgroup?zid=' + zid,
    //   })
    // } else {
      wx.navigateTo({
        url: '/hyb_yl/mysubpages/pages/patientman/patientman?state=' + state + '&zid=' + zid,
      })
    // }
  },
  saveImage: function (e) {
    let url = e.currentTarget.dataset.url;
    console.log(e);
    wx.getImageInfo({
      src: url,
      success: (res) => {
        let path = res.path;
        wx.saveImageToPhotosAlbum({
          filePath: path,
          success(res) {
            console.log(res);
          },
          fail: (res) => {
            console.log(res);
          }
        })
      },
      fail: (res) => {
        console.log(res);
      }
    })

  },
  zsservice: function (e) {
    var that = this
    const url = e.currentTarget.dataset.url;
    var zid = that.data.zid
    console.log(e)
    wx.navigateTo({
      url: url + '?zid=' + zid
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    template.tabbar("tabBar", 0, this)
    var that = this
    //执行号码绑定
    app.util.request({
      'url': 'entry/wxapp/index.base',
      success: function (res) {
        console.log(res)
        that.setData({
          base: res.data
        })
      }
    })
    that.getDocinfo()
    var bgc = wx.getStorageSync('color')
    this.setData({
      bg_color:bgc
    })
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: bgc,
    })
  },
  
  closeshare: function () {
    this.setData({
      isopera: false
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getDocinfo()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
  getDocinfo(e) {
    var that = this
    app.util.request({
      'url': 'entry/wxapp/green.guidance_detail',
      data: {
        openid: wx.getStorageSync('openid'),
      },
      success: function (res) {
        
        var did = res.data.id
        wx.setStorageSync('did', did)
        that.setData({
          docinfo: res.data,
          id: res.data.id,
          thumb:res.data.thumb
        })
      }
    })
  },
  getDoc() {
    var that = this
    app.util.request({
      'url': 'entry/wxapp/studio.ifzj',
      data: {
        openid: wx.getStorageSync('openid'),
      },
      success: function (res) {
        console.log(res)
        if (res.data == 1) {
          wx.setStorage({
            key: 'userinfotype',
            data: 'doc',
          })
        }
      }
    })
  },
  goExplanation: function () {
    var that = this;
    var zid = that.data.zid
    var sate = 1
    wx.setStorageSync('sate', sate)
    wx.navigateTo({
      url: "/hyb_yl/backstageFollowUp/pages/explanation/explanation?zid=" + zid,
      success: function () {
        that.setData({
          nonReadBoo: !0
        });
      }
    });
  },
  hzwenzhen(e) {
    var that = this
    console.log(e)
    var title = e.currentTarget.dataset.title
    var keyword = e.currentTarget.dataset.keyword
    var did = e.currentTarget.dataset.did
    wx.navigateTo({
      url: '/hyb_yl/lvtongserver/pages/docorder/docorder?title=' + title + '&keyword=' + keyword + '&did=' + did,
    })
  },
  goBack: function (e) {
    var that = this
    console.log(e)
    var titlme = e.currentTarget.dataset.titlme
    var key_words = e.currentTarget.dataset.key_words
    var id = e.currentTarget.dataset.id
    var zid = that.data.zid


    wx.navigateTo({
      url: '/hyb_yl/mysubpages/pages/serviceList/serviceList?titlme=' + titlme + '&key_words=' + key_words + '&id=' + id + '&zid=' + zid,
    })
  },
})